[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
ldexp() Convert Mantissa and Exponent to Floating Point
#include <math.h>
double ldexp(m,exp);
double m; Floating-point value
int exp; Integer exponent
ldexp() returns the result of the calculation:
'm' * 2^ 'exp'
where ^ means "raised to the power of".
Returns: 'm' * 2^ 'exp'. On overflow, 'errno' (defined in
<errno.h>) is set to ERANGE (defined in <errno.h>),
and the value HUGE_VAL (+ or -, depending on the sign
of 'm') is returned. (HUGE_VAL is defined in math.h.)
On underflow 0.0 is returned ('errno' is not set on
underflow).
Notes: frexp() breaks a floating-point value into mantissa
and exponent.
You can modify error handling with the matherr()
routine.
-------------------------------- Example ---------------------------------
The following statements calculate the values of 1.0 * 2^24, 6.5 *
2^-10, -2.0 * 2^0, and 9.9e99 * 2^999 (the last calculation
produces an OVERFLOW error):
#include <math.h> /* for ldexp() and ERANGE */
#include <stdio.h> /* for printf() */
#include <errno.h> /* for errno */
main()
{
double a, b, c, d;
a = ldexp(1.0, 24); /* a = 16777216.0 */
b = ldexp(6.5, -10); /* b = 0.0063477 */
c = ldexp(-2.0, 0); /* c = -2.0 */
errno = 0;
/* d = HUGE_VAL, causes an OVERFLOW error */
d = ldexp(9.9e99, 999); if (errno == ERANGE)
printf("OVERFLOW error in ldexp()\n");
}
See Also:
frexp()
modf()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson